#include <iostream>
#include <time.h>

int main(){
	double dur;
	clock_t start,end;
	long long n,m;
    std::cin>>n>>m;
	start=clock();
	
    long long ret = 0;
	for (long long i = 2; i <= n; i++) {
		ret = (ret + m) % i;
	}
	std::cout<<ret<<std::endl;
	end=clock();
	dur=(double) end-start;
	std::cout<<dur<<std::endl;
    return 0;
}